// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Common from "../Common";
import {isEmpty} from "../common/Helpers";

const {ccclass, property} = cc._decorator;

@ccclass
export default class PrizePool extends Common {

    @property(cc.Node)
    backBtn: cc.Node = null

    @property(cc.Label)
    accBonusLabel: cc.Label = null;

    @property(cc.Label)
    prizePoolLabel: cc.Label = null;


    @property(cc.Label)
    prizeDescLabel: cc.Label = null;

    accBonusText: string = '累计分红：{##}';
    rationText: string = '当日{##}%现金将进入奖金池';

    start() {
        this.backBtn.on(cc.Node.EventType.TOUCH_START, () => {
            this.onBtnClick()
            this.goToHall()
        }, this) // 点击返回首页按钮
        this.init()
    }

    async init() {
        try {
            const {data} = await this.http.get('bonus/setting')
            if (!isEmpty(data)) {
                this.prizePoolLabel.string = data.today_prize_pool || '0.00'
                this.accBonusLabel.string = this.accBonusText.replace('{##}', data.acc_bonus || '0.00')
                this.prizeDescLabel.string = this.rationText.replace('{##}', data.share_prize_ration || '0.00')
            }
        } catch (e) {

        }
    }

}
